<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Template_model extends OC_Model {

	function get_all($params = array())
	{
		$this->db->select('SQL_CALC_FOUND_ROWS *', FALSE);
		$this->db->from('templates');

		if (isset($params['sort'], $params['order']))
			$this->db->order_by($params['sort'], $params['order']);

		if (isset($params['page'], $params['rows']))
			$this->db->limit($params['rows'], (intval($params['page']-1)*intval($params['rows'])));

		if (isset($params['query']) && $params['query'] != '')
		{
			$query = $params['query'];

			$likes = array_map(
				function($f) use ($query) { return "$f LIKE '%$query%'"; }, 
				array('tpl_name', 'tpl_content')
			);
			
			$this->db->where('('.implode(' OR ', $likes).')');
		}

		return $this->fetch_rows();

	}

	function add($data)
	{
		return $this->db->insert('templates', $data);
	}

	function edit($data, $keys)
	{
		return $this->db->update('templates', $data, $keys);
	}

	function delete($keys)
	{
		return $this->db->delete('templates', $keys);
	}

}

/* End of file page_model.php */
/* Location: .//D/noobsprojects/swanstwenty/dnetnorfintek/module_admin/templates/models/page_model.php */